import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';
import {toast} from 'nc-lightapp-front';

export default function afterTableEdit(areaCode, key, model, oldValue, index) {
    const {orgVal, editTable, func_type} = this.props;
    let postData = {
        areaCode,
        func_type,
        editType: this.editType,
        pk_org: orgVal.refpk,
        key,
        oldValue,
        model: {areacode: areaCode, rows: [model]}
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsLineAfterEditAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                if (res.data.errMsg) {
                    toast({
                        color: 'danger',
                        content: res.data.errMsg
                    });
                    editTable.setRowByIndex(areaCode, res.data.rowData[areaCode].rows[0], index);
                } else {
                    editTable.setRowByIndex(areaCode, res.data.rowData[areaCode].rows[0], index);
                    if (res.data.isJobGradeItemEdit === true || res.data.isJobGradeItemEdit === false) {
                        editTable.setEditableRowKeyByIndex(areaCode, index, 'pk_jobgrade', res.data.isJobGradeItemEdit)
                    }
                }
            }
        });
}
